package com.ruoyi;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 启动程序
 *
 * @author ruoyi
 */
@Slf4j
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class RuoYiApplication {
    public static void main(String[] args) throws UnknownHostException {
        // 处理nacos 和 服务logback冲突: Context has been already given a name
        System.setProperty("nacos.logging.default.config.enabled", "false");

        ConfigurableApplicationContext application = SpringApplication.run(RuoYiApplication.class, args);

        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");

        String applicationName = env.getProperty("spring.application.name");
        String profiles = env.getProperty("spring.profiles.active");

        log.info("\n----------------------------------------------------------\n\t" +
                "Application " + applicationName + ":" + profiles + " is running! \n\t" +
                "Access URLs:\n\t" +
                "Local: \t\thttp://localhost:" + port + path + "/\n\t" +
                "External: \thttp://" + ip + ":" + port + path + "/\n\t" +
                "----------------------------------------------------------");
    }
}
